<template>
	<cl-crud ref="Crud">
		<cl-row>
			<!-- 刷新按钮 -->
			<cl-refresh-btn />
			<!-- 新增按钮 -->
			<cl-add-btn />
			<!-- 删除按钮 -->
			<cl-multi-delete-btn />
			<cl-flex1 />
			<!-- 关键字搜索 -->
			<cl-search-key />
		</cl-row>

		<cl-row>
			<!-- 数据表格 -->
			<cl-table ref="Table" />
		</cl-row>

		<cl-row>
			<cl-flex1 />
			<!-- 分页控件 -->
			<cl-pagination />
		</cl-row>

		<!-- 新增、编辑 -->
		<cl-upsert ref="Upsert" />
	</cl-crud>
</template>

<script lang="ts" name="demo-ship_data" setup>
import { useCrud, useTable, useUpsert } from "@cool-vue/crud";
import { useCool } from "/@/cool";

const { service } = useCool();

// cl-upsert
const Upsert = useUpsert({
	items: [
		{ prop: "shipId", label: "船的编号", required: true, component: { name: "el-input" } },
		{ prop: "sn", label: "船系列号", required: true, component: { name: "el-input" } },
		{ prop: "pitchAngle", label: "俯仰角", required: true, component: { name: "el-input" } },
		{ prop: "obliqueAngle", label: "侧倾角", required: true, component: { name: "el-input" } },
		{ prop: "lng", label: "经度", required: true, component: { name: "el-input" } },
		{ prop: "lat", label: "纬度", required: true, component: { name: "el-input" } },
		{
			prop: "slidingDistance",
			label: "滑行距离",
			required: true,
			component: { name: "el-input" }
		},
		{ prop: "averageSpeed", label: "平均船速", required: true, component: { name: "el-input" } }
	]
});

// cl-table
const Table = useTable({
	columns: [
		{ type: "selection" },
		{ prop: "id", label: "ID" },
		{ prop: "shipId", label: "船的编号" },
		{ prop: "sn", label: "船系列号" },
		{ prop: "pitchAngle", label: "俯仰角" },
		{ prop: "obliqueAngle", label: "侧倾角" },
		{ prop: "lng", label: "经度" },
		{ prop: "lat", label: "纬度" },
		// { prop: "slidingDistance", label: "滑行距离" },
		// 目前存的是船实际速度
		{ prop: "averageSpeed", label: "船速" },
		{ prop: "createTime", label: "创建时间", sortable: "desc", width: 160 },
		// { prop: "updateTime", label: "更新时间", sortable: "custom", width: 160 },
		{ type: "op", buttons: ["edit", "delete"] }
	]
});

// cl-crud
const Crud = useCrud(
	{
		service: service.demo.ship_data
	},
	(app) => {
		app.refresh();
	}
);
</script>
